package com.SMS;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;




public class datastore{
	
	private final static String dbname = "SMS";
	private final static String tablename = "history";
	
	private final static int version = 2;
	private final static String id = "_id";
	
	private SQLiteDatabase SQLite;
	private Context ctx;
	private com.SMS.datastore.DatabaseHelper helper;
	
	private static String createDatabase = "create table history(_id integer primary key Autoincrement, phonenumber text not null,message text not null)";
	
	private static class DatabaseHelper extends SQLiteOpenHelper {
		
	    DatabaseHelper(Context context) { super(context, dbname, null, version); }
	
	    @Override
	    public void onCreate(SQLiteDatabase db) { db.execSQL(createDatabase); }
	
	    @Override
	    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { onCreate(db); }
	}
	
	public datastore(Context ctx){ this.ctx = ctx; }
	
	public  datastore openDB(){
		helper = new DatabaseHelper(ctx);
		SQLite = helper.getWritableDatabase();
		return this;
	}
	
public void close() { helper.close(); }
	
	public long Insert(String phonenumber,String message){
		ContentValues values = new ContentValues();
		values.put("phonenumber",phonenumber);
		values.put("message", message);
		return SQLite.insert(tablename, null, values);
	}
	

}
